package com.ruoyi.jihuo.api;

import com.ruoyi.jihuo.api.official.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ruoyi.jihuo.constant.TaoApiConstant.*;

@Component
public class ApiStrategyContext {

    private final Map<String, ApiStrategy> strategyMap = new HashMap<>();

    @Autowired
    public ApiStrategyContext(List<ApiStrategy> strategies) {
        // 这里可以结合 Bean 名称或自定义注解进行更精确的映射
        strategies.forEach(strategy -> {
            if (strategy instanceof ItemsOnsaleGetStrategy) {
                strategyMap.put(GET_ITEMS_ON_SALE_API, strategy);
            } else if (strategy instanceof ItemSellerGetStrategy) {
                strategyMap.put(QUERY_ITEM_INFO_API, strategy);
            } else if (strategy instanceof GetItemAuthorizedStrategy) {
                strategyMap.put(GET_ITEMS_AUTHORIZED_API, strategy);
            } else if (strategy instanceof GetAddProductSchemaStrategy) {
                strategyMap.put(GET_ADD_PRODUCT_SCHEMA_API, strategy);
            } else if (strategy instanceof TmallProductSchemaAddStrategy) {
                strategyMap.put(ADD_PRODUCT_API, strategy);
            } else if (strategy instanceof TmallProductSchemaGetStrategy) {
                strategyMap.put(GET_PRODUCT_SCHEMA_API, strategy);
            } else if (strategy instanceof AlibabaItemPublishSchemaGetStrategy) {
                strategyMap.put(GET_SUBMIT_ITEM_SCHEMA_API, strategy);
            } else if (strategy instanceof AlibabaItemPublishSubmitStrategy) {
                strategyMap.put(SUBMIT_ITEM_API, strategy);
            } else if (strategy instanceof PictureUploadStrategy) {
                strategyMap.put(UPLOAD_PICTURE_API, strategy);
            }else if (strategy instanceof TaobaoDeliveryTemplatesGetStrategy) {
                strategyMap.put(TAOBAO_DELIVERY_TEMPLATES_GET_API, strategy);
            }
            // 其他 API 添加到这里...
        });
    }

    public ApiStrategy getStrategy(String apiName) {
        return strategyMap.get(apiName);
    }
}
